//
//  NSBundle + Extension.swift
//  微博新浪
//
//  Created by hezerong on 16/6/11.
//  Copyright © 2016年 Rocky. All rights reserved.
//        return NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"]! as! String


import Foundation

//key值
let versionUserDefaultKey = "CFBundleShortVersionString"

extension NSBundle{
  
    //获取当前的版本号
    class func getCurrentVersion() ->String{
    
        return NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"]! as! String
    
    }
    
    //存储当前的版本号
   class func saveCurrentVersion(){
    
        let currentVersion = getCurrentVersion()
        
        NSUserDefaults.standardUserDefaults().setValue(currentVersion, forKey: versionUserDefaultKey)
    
    }
    
    //检查是否是最新版本
  class  func checkIfNewVersion() ->Bool{
        
        let savedVersion = NSUserDefaults.standardUserDefaults().objectForKey(versionUserDefaultKey) as? String
        
        let currentVersion = getCurrentVersion()
        
        //保存当前版本
        saveCurrentVersion()
    

        
        return (savedVersion == nil || currentVersion > savedVersion) ? true : false
        
    }


}